package pl.pages;

import java.util.List;

import org.apache.tapestry.IPage;
import org.apache.tapestry.annotations.InjectPage;
import org.apache.tapestry.annotations.InjectState;
import org.apache.tapestry.dojo.form.IAutocompleteModel;
import org.apache.tapestry.form.IPropertySelectionModel;
import org.apache.tapestry.html.BasePage;

import pl.model.AutoModel;
import pl.model.Celebrity;
import pl.model.CelebrityModel;
import pl.model.DataSource;

@SuppressWarnings("unused")
public abstract class CelebritiesList extends BasePage {

	// private DataSource dataSource = new DataSource();
	@InjectState("dataSource")
	public abstract DataSource getDataSource();

	@InjectState("celebrityOfTheWeek")
	public abstract Celebrity getCelebrityOfTheWeek();

	@InjectPage("Details")
	public abstract Details getDetailsPage();

	@SuppressWarnings("unchecked")
	public List getCelebrities() {

		return getDataSource().getCelebrities();
	}

	public IPage onShowDetails(int id, String name) {

		Celebrity celebrity = getDataSource().getCelebrityById(id);

		Details nextPage = getDetailsPage();

		System.out.println("setting to details celebrity: " + celebrity);
		
		nextPage.setCelebrity(celebrity);
		return nextPage;

		// public IPage onShowDetails(IRequestCycle cycle)
		// Details page = (Details) cycle.getPage("Secret");
		// page.setCelebrity(celebrity);

	}

	public IPropertySelectionModel getCelebrityModel() {

		return new CelebrityModel(getCelebrities());
	}

	public String onSaveCelebrityOfTheWeek() {

		return "Home";
	}

	public IAutocompleteModel getAutoModel() {

		return new AutoModel(getCelebrities());
	}
}
